; generated by ARM C/C++ Compiler with , RVCT4.0 [Build 524] for uVision
; commandline ArmCC [--split_sections --debug -c --asm --interleave -oaduc702x_spi.o --depend=aduc702x_spi.d --device=DARMAD -I.\inc -I.\efsl-0.2.8\inc -I.\efsl-0.2.8\conf -IC:\Keil\ARM\INC\ADI -D__MICROLIB -D__KEIL__ efsl-0.2.8\src\interfaces\aduc702x_spi.c]
                          ARM

                          AREA ||i.if_initInterface||, CODE, READONLY, ALIGN=2

                  if_initInterface PROC
;;;52     
;;;53     esint8 if_initInterface(hwInterface* file, eint8* opts)
000000  e92d4038          PUSH     {r3-r5,lr}
;;;54     {
000004  e1a04000          MOV      r4,r0
;;;55     	euint32 sc;
;;;56     	
;;;57     	if_spiInit(file); /* init at low speed */
000008  ebfffffe          BL       if_spiInit
;;;58     	
;;;59     	if(sd_Init(file)<0)	{
00000c  e1a00004          MOV      r0,r4
000010  ebfffffe          BL       sd_Init
000014  e3500000          CMP      r0,#0
000018  aa000003          BGE      |L1.44|
;;;60     		DBG("Card failed to init, breaking up...\n");
00001c  e28f0060          ADR      r0,|L1.132|
000020  ebfffffe          BL       debug_printf
;;;61     		return(-1);
000024  e3e00000          MVN      r0,#0
;;;62     	}
;;;63     
;;;64     	if(sd_State(file)<0){
;;;65     		DBG("Card didn't return the ready state, breaking up...\n");
;;;66     		return(-2);
;;;67     	}
;;;68     	
;;;69     	// file->sectorCount=4; /* FIXME ASAP!! */
;;;70     	
;;;71     	sd_getDriveSize(file, &sc);
;;;72     	file->sectorCount = sc/512;
;;;73     	if( (sc%512) != 0) {
;;;74     		file->sectorCount--;
;;;75     	}
;;;76     #ifdef FS_DEBUG_DEFINE
;;;77     	DEBUG_PRINTF("Drive Size is %lu Bytes (%lu Sectors)\n", sc, file->sectorCount);
;;;78     #endif
;;;79     	
;;;80     	 /* increase speed after init */
;;;81     	if_spiSetSpeed(SPI_PRESCALE_MIN);
;;;82     
;;;83     #ifdef FS_DEBUG_DEFINE
;;;84     	DBG("Init done...\n");
;;;85     #endif
;;;86     	return(0);
;;;87     }
000028  e8bd8038          POP      {r3-r5,pc}
                  |L1.44|
00002c  e1a00004          MOV      r0,r4                 ;64
000030  ebfffffe          BL       sd_State
000034  e3500000          CMP      r0,#0                 ;64
000038  aa000003          BGE      |L1.76|
00003c  e28f0068          ADR      r0,|L1.172|
000040  ebfffffe          BL       debug_printf
000044  e3e00001          MVN      r0,#1                 ;66
000048  e8bd8038          POP      {r3-r5,pc}
                  |L1.76|
00004c  e1a0100d          MOV      r1,sp                 ;71
000050  e1a00004          MOV      r0,r4                 ;71
000054  ebfffffe          BL       sd_getDriveSize
000058  e59d0000          LDR      r0,[sp,#0]            ;72
00005c  e1a004a0          LSR      r0,r0,#9              ;72
000060  e5840000          STR      r0,[r4,#0]            ;73
000064  e59d1000          LDR      r1,[sp,#0]            ;73
000068  e1b01b81          LSLS     r1,r1,#23             ;73
00006c  12400001          SUBNE    r0,r0,#1              ;74
000070  15840000          STRNE    r0,[r4,#0]            ;74
000074  e3a00005          MOV      r0,#5                 ;81
000078  ebfffffe          BL       if_spiSetSpeed
00007c  e3a00000          MOV      r0,#0                 ;86
000080  e8bd8038          POP      {r3-r5,pc}
;;;88     /*****************************************************************************/ 
                          ENDP

                  |L1.132|
000084  43617264206661696c656420746f20696e69742c20627265616b696e672075702e2e2e0a00        DCB      "Card failed to init, breaking up...\n",0
0000a9  00                DCB      0
0000aa  00                DCB      0
0000ab  00                DCB      0
                  |L1.172|
0000ac  43617264206469646e27742072657475726e207468652072656164792073746174652c20627265616b696e672075702e2e2e0a00        DCB      "Card didn't return the ready state, breaking up...\n",0

                          AREA ||i.if_readBuf||, CODE, READONLY, ALIGN=2

                  if_readBuf PROC
;;;89     
;;;90     esint8 if_readBuf(hwInterface* file,euint32 address,euint8* buf)
000000  e3a03c02          MOV      r3,#0x200
;;;91     {
;;;92     	return(sd_readSector(file,address,buf,512));
000004  eafffffe          B        sd_readSector
;;;93     }
;;;94     /*****************************************************************************/
                          ENDP


                          AREA ||i.if_setPos||, CODE, READONLY, ALIGN=2

                  if_setPos PROC
;;;101    
;;;102    esint8 if_setPos(hwInterface* file,euint32 address)
000000  e3a00000          MOV      r0,#0
;;;103    {
;;;104    	return(0);
;;;105    }
000004  e12fff1e          BX       lr
;;;106    /*****************************************************************************/ 
                          ENDP


                          AREA ||i.if_spiInit||, CODE, READONLY, ALIGN=2

                  if_spiInit PROC
;;;123    
;;;124    void if_spiInit(hwInterface *iface)
000000  e3a00000          MOV      r0,#0
;;;125    {
000004  e52de004          PUSH     {lr}
;;;126            int i; 
;;;127    	unsigned long gpmode;
;;;128    	// setup GPIO
;;;129    	gpmode = GP1CON; // setup pins for SCK, MISO, MOSI
000008  e5101bfc          LDR      r1,[r0,#-0xbfc]
;;;130    	GP1CON = (gpmode & 0xf000ffff) | 0x02220000;
00000c  e3c1140f          BIC      r1,r1,#0xf000000
000010  e3c118ff          BIC      r1,r1,#0xff0000
000014  e3811402          ORR      r1,r1,#0x2000000
000018  e3811822          ORR      r1,r1,#0x220000
00001c  e5001bfc          STR      r1,[r0,#-0xbfc]
;;;131    #ifdef chris
;;;132    	gpmode = GP3CON; // setup pins for CS
;;;133    	GP3CON = gpmode & 0xffffff0f;  // make it GPIO
;;;134    	gpmode = GP3DAT;
;;;135    	GP3DAT = gpmode | 0x02020000; // make bit 2 output and high
;;;136    #else
;;;137    	gpmode = GP1CON; // setup pins for CS
000020  e5101bfc          LDR      r1,[r0,#-0xbfc]
;;;138    	GP1CON = gpmode & 0x0fffffff;  // make it GPIO
000024  e3c1120f          BIC      r1,r1,#0xf0000000
000028  e5001bfc          STR      r1,[r0,#-0xbfc]
;;;139    	gpmode = GP1DAT;
00002c  e5101bd0          LDR      r1,[r0,#-0xbd0]
;;;140    	GP1DAT = gpmode | 0x80800000; // make bit 2 output and high
000030  e3811102          ORR      r1,r1,#0x80000000
000034  e3811502          ORR      r1,r1,#0x800000
000038  e5001bd0          STR      r1,[r0,#-0xbd0]
;;;141    #endif
;;;142    
;;;143    	// set Chip-Select high - unselect card
;;;144    	UNSELECT_CARD();
00003c  e3a01502          MOV      r1,#0x800000
000040  e5001bcc          STR      r1,[r0,#-0xbcc]
;;;145    	//configure the SPI
;;;146            SPICON = 0x1043; //enable, master CPOL=0 CPHA=0
000044  e59f0038          LDR      r0,|L4.132|
000048  e2412881          SUB      r2,r1,#0x810000
00004c  e5820a10          STR      r0,[r2,#0xa10]
;;;147    	// low speed during init
;;;148    	if_spiSetSpeed(20); // 1 mhz 
000050  e3a00014          MOV      r0,#0x14
000054  ebfffffe          BL       if_spiSetSpeed
;;;149    
;;;150    	/* Send 20 spi commands with card not selected */
;;;151    	for(i=0;i<21;i++) {
000058  e3a00000          MOV      r0,#0
00005c  e3a030ff          MOV      r3,#0xff
                  |L4.96|
000060  e5823a08          STR      r3,[r2,#0xa08]
                  |L4.100|
000064  e5921a00          LDR      r1,[r2,#0xa00]
000068  e3110008          TST      r1,#8
00006c  0afffffc          BEQ      |L4.100|
000070  e5921a04          LDR      r1,[r2,#0xa04]
000074  e2800001          ADD      r0,r0,#1
000078  e3500015          CMP      r0,#0x15
00007c  bafffff7          BLT      |L4.96|
;;;152    	  my_if_spiSend(iface,0xff);
;;;153    	}
;;;154    	
;;;155    }
000080  e49df004          POP      {pc}
;;;156    /*****************************************************************************/
                          ENDP

                  |L4.132|
                          DCD      0x00001043

                          AREA ||i.if_spiSend||, CODE, READONLY, ALIGN=2

                  if_spiSend PROC
;;;165    
;;;166    euint8 if_spiSend(hwInterface *iface, euint8 outgoing)
000000  e3a02502          MOV      r2,#0x800000
;;;167    {
;;;168    	euint8 incoming;
;;;169    
;;;170    	SELECT_CARD();
000004  e3a03000          MOV      r3,#0
000008  e5032bc8          STR      r2,[r3,#-0xbc8]
;;;171    	SPITX = (euint8) outgoing;
00000c  e2420881          SUB      r0,r2,#0x810000
000010  e5801a08          STR      r1,[r0,#0xa08]
                  |L5.20|
;;;172    	while((SPISTA & 0x08) != 0x08);
000014  e5901a00          LDR      r1,[r0,#0xa00]
000018  e3110008          TST      r1,#8
00001c  0afffffc          BEQ      |L5.20|
;;;173     	incoming = (euint8) SPIRX;
000020  e5900a04          LDR      r0,[r0,#0xa04]
;;;174    	UNSELECT_CARD();
000024  e5032bcc          STR      r2,[r3,#-0xbcc]
000028  e20000ff          AND      r0,r0,#0xff           ;173
;;;175    
;;;176    	return(incoming);
;;;177    }
00002c  e12fff1e          BX       lr
;;;178    /*****************************************************************************/
                          ENDP


                          AREA ||i.if_spiSetSpeed||, CODE, READONLY, ALIGN=2

                  if_spiSetSpeed PROC
;;;157    
;;;158    void if_spiSetSpeed(euint16 speed)
000000  e59f100c          LDR      r1,|L6.20|
;;;159    {
;;;160    	if ( speed < SPI_PRESCALE_MIN  ) speed = SPI_PRESCALE_MIN ;
000004  e3500005          CMP      r0,#5
000008  33a00005          MOVCC    r0,#5
;;;161    	SPIDIV = speed;
00000c  e5810a0c          STR      r0,[r1,#0xa0c]
;;;162    }
000010  e12fff1e          BX       lr
;;;163    
                          ENDP

                  |L6.20|
                          DCD      0xffff0000

                          AREA ||i.if_writeBuf||, CODE, READONLY, ALIGN=2

                  if_writeBuf PROC
;;;95     
;;;96     esint8 if_writeBuf(hwInterface* file,euint32 address,euint8* buf)
000000  eafffffe          B        sd_writeSector
;;;97     {
;;;98     	return(sd_writeSector(file,address, buf));
;;;99     }
;;;100    /*****************************************************************************/ 
                          ENDP

